<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\Dashboard;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Encore\Admin\Widgets\Box;
use Encore\Admin\Widgets\InfoBox;
use Illuminate\Support\Facades\DB;
use App\Models\Squad;
use App\Models\Notice;

class HomeController extends Controller
{
    public function index()
    {
         return Admin::content(function (Content $content) {
            $content->header('首页');
            $content->description(' ');
			if (Admin::user()->id == 1) {
                $content->row(view('admin.clear_excel'));
            }
            $content->row(function (Row $row) {
                $admin_id = Admin::user()->id;
                $my_squad_ids = squad::where('class_teacher',$admin_id)->pluck('id')->toArray();
                //dd($my_squad_ids);
                for ($i=0; $i < count($my_squad_ids); $i++) {
                    $squad_id = $my_squad_ids[$i];
                    $my_squad_name = Squad::where('id',$squad_id)->value('name');
					$squad_stage = DB::table('squads as s')
						->leftJoin('class_section_groups as c','s.section','=','c.id')
						->value('c.name');
					if($squad_stage == "一段班") {
						$color = "blue";
					}else{
						$color = "green";
					}
                    $total_num = Notice::where('squad_id',$squad_id)->whereIn('status',['1','3'])->count();
                    $attendance_num = Notice::where('squad_id',$squad_id)->where('notice_type','1')->whereIn('status',['1','3'])->count();
                    $test_num = Notice::where('squad_id',$squad_id)->where('notice_type','2')->whereIn('status',['1','3'])->count();
                    $jiaxiao_num = Notice::where('squad_id',$squad_id)->where('notice_type','3')->whereIn('status',['1','3'])->count();
                    $dictation_num = Notice::where('squad_id',$squad_id)->where('notice_type','4')->whereIn('status',['1','3'])->count();
                    $zuoye_num = Notice::where('squad_id',$squad_id)->where('notice_type','5')->whereIn('status',['1','3'])->count();
                    $jindu_num = Notice::where('squad_id',$squad_id)->where('notice_type','6')->whereIn('status',['1','3'])->count();
                    $icon_arr = array('users','shopping-cart','book','file','apple','diamond');
                    $icon = $icon_arr[array_rand($icon_arr)];
                    $total_link = '/admin/my_squad/'.$squad_id;
                    $attendance_link = '/admin/my_todo_notices?squad_id%5B%5D='.$squad_id.'&notice_type%5B%5D=1&status%5B%5D=1&status%5B%5D=3';
                    $test_link = '/admin/my_todo_notices?squad_id%5B%5D='.$squad_id.'&notice_type%5B%5D=2&status%5B%5D=1&status%5B%5D=3';
                    $jiaxiao_link = '/admin/my_todo_notices?squad_id%5B%5D='.$squad_id.'&notice_type%5B%5D=3&status%5B%5D=1&status%5B%5D=3';
                    $dictation_link = '/admin/my_todo_notices?squad_id%5B%5D='.$squad_id.'&notice_type%5B%5D=4&status%5B%5D=1&status%5B%5D=3';
                    $zuoye_link = '/admin/my_todo_notices?squad_id%5B%5D='.$squad_id.'&notice_type%5B%5D=5&status%5B%5D=1&status%5B%5D=3';
                    $jindu_link = '/admin/my_todo_notices?squad_id%5B%5D='.$squad_id.'&notice_type%5B%5D=6&status%5B%5D=1&status%5B%5D=3';
                    $row->column(3, new InfoBox($my_squad_name, $icon, $color, $total_link,$attendance_link,$test_link,$jiaxiao_link,$dictation_link,$zuoye_link,$jindu_link, $total_num, $attendance_num, $test_num, $jiaxiao_num, $dictation_num, $zuoye_num ,$jindu_num,$squad_id));
                }
            });
            $content->row(function (Row $row) {
                 $row->column(7, function (Column $column) {
                     $column->append(Dashboard::box());
                 });
                 $row->column(5,function(Column $column){


                    $column->append(Dashboard::sp_box());
                 });
             });
/*            $content->row(function (Row $row) {
                $row->column(5, function (Column $column) {
                    $column->append(Dashboard::box());
                });
                $row->column(7, function (Column $column) {
                    $column->append(Dashboard::xiaoli());
                });
            });*/
            if (Admin::user()->can('xun_chang')) {
                $content->row(Dashboard::xc_box());
            }

            //$content->row(Dashboard::xc_box());
            $content->row(Dashboard::kebiao());

            $content->row(function (Row $row) {
                 $row->column(7, function (Column $column) {
                     $column->append(Dashboard::xiaoli());
                 });
             });
            //$content->row(Dashboard::CheckNews());
         });
    }

    protected function showFormParameters($content)
    {
        $parameters = request()->except(['_pjax', '_token']);

        if (!empty($parameters)) {

            ob_start();

            dump($parameters);

            $contents = ob_get_contents();

            ob_end_clean();

            $content->row(new Box('Form parameters', $contents));
        }
    }
}
